package top.lixunda.ecommerce.server.good.api.entity.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.good.api.entity.db.SimpleReviewDO;
import top.lixunda.ecommerce.server.good.api.entity.db.SimpleReviewDetailDO;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 简单评论数据
 *
 * @author Xumda
 * @version time:2020/1/14 15:48
 */
@SuppressWarnings({"WeakerAccess", "unused"})
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class SimpleReviewVO {

    @ApiModelProperty(value = "唯一id")
    private Integer id;

    @ApiModelProperty(value = "用户id")
    private Integer userId;

    @ApiModelProperty(value = "用户名称")
    private String userName;

    @ApiModelProperty(value = "店铺id")
    private Integer storeId;

    @ApiModelProperty(value = "店铺名称")
    private String storeName;

    @ApiModelProperty(value = "商品id")
    private Integer goodId;

    @ApiModelProperty(value = "商品名称")
    private String goodName;

    @ApiModelProperty(value = "评分")
    private Integer score;

    @ApiModelProperty(value = "评论内容")
    private String content;

    @ApiModelProperty(value = "评论创建时间，即发表评论时间")
    private LocalDateTime time;

    @ApiModelProperty(value = "删除时间")
    private LocalDateTime removeTime;

    @ApiModelProperty(value = "删除人员id")
    private Integer removeUserId;

    @ApiModelProperty(value = "删除人员名称")
    private String removeUserName;

    @ApiModelProperty(value = "评论点赞次数")
    private Integer praise;

    public static SimpleReviewVO fromSimpleReviewDO(SimpleReviewDO simpleReviewDO) {
        if (ObjectValidators.isEmpty(simpleReviewDO)) {
            return null;
        }
        SimpleReviewVO simpleReviewVO = new SimpleReviewVO();
        BeanUtils.copyProperties(simpleReviewDO, simpleReviewVO);
        return simpleReviewVO;
    }

    public static List<SimpleReviewVO> fromSimpleReviewDO(List<SimpleReviewDO> simpleReviewDO) {
        if (simpleReviewDO == null) {
            return null;
        }
        return simpleReviewDO.stream().map(SimpleReviewVO::fromSimpleReviewDO)
                .filter(Objects::nonNull).collect(Collectors.toList());
    }

    public static SimpleReviewVO fromSimpleReviewDetailDO(SimpleReviewDetailDO simpleReviewDO) {
        if (ObjectValidators.isEmpty(simpleReviewDO)) {
            return null;
        }
        SimpleReviewVO simpleReviewVO = new SimpleReviewVO();
        BeanUtils.copyProperties(simpleReviewDO, simpleReviewVO);
        return simpleReviewVO;
    }

    public static List<SimpleReviewVO> fromSimpleReviewDetailDO(List<SimpleReviewDetailDO> simpleReviewDO) {
        if (simpleReviewDO == null) {
            return null;
        }
        return simpleReviewDO.stream().map(SimpleReviewVO::fromSimpleReviewDetailDO)
                .filter(Objects::nonNull).collect(Collectors.toList());
    }
}
